<form action='{:url("save")}' method="post" data-auto="true" class="layui-form layui-card" data-table-id="VisitorTable">
    <div class="layui-card-body padding-left-40">

        <label class="layui-form-item relative block">
            <span class="help-label"><b>公司</b></span>
            <select name="company_id" class="layui-select" required>
                <option value="">请选择公司</option>
                {volist name="companies" id="company"}
                <option value="{$company.id}" {if condition="isset($vo) && ($vo.company_id == $company.id)"}selected{/if}>{$company.name}</option>
                {/volist}
            </select>
        </label>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>车牌号</b></span>
            <input maxlength="255" class="layui-input" name="plate_number" value="{$vo.plate_number|default=''}" required placeholder="请输入车牌号">
        </label>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>分配时长</b></span>
            <input type="number" min="0" class="layui-input" name="free_hours" value="{$vo.free_hours|default=''}" required placeholder="请输入分配时长">
        </label>

    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit' lay-submit lay-filter="save">保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>

{block name='script'}
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;

        form.on('submit(save)', function (data) {
            $.post(data.form.action, data.field, function (res) {
                if (res.code === 2) {
                    layer.confirm(res.info, {
                        btn: ['继续添加', '取消']
                    }, function () {
                        $.post('{:url("confirm")}', {
                            parking_record_id: res.data.parking_record_id,
                            free_hours: res.data.additional_data.free_hours,
                            additional_data: res.data.additional_data
                        }, function (confirmRes) {
                            if (confirmRes.code === 1) {
                                layer.msg(confirmRes.info, {icon: 1, time: 2000}, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(confirmRes.info, {icon: 2, time: 2000});
                            }
                        });
                    });
                } else if (res.code === 1) {
                    layer.msg(res.info, {icon: 1, time: 2000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(res.info, {icon: 2, time: 2000});
                }
            });
            return false;
        });
    });
</script>
{/block}
